package com.bjc.principle.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: DesignPattern
 * @description: 贷款人
 * @author: bjc
 * @create: 2021-01-04 13:33
 */
public class ZhangSan implements Debit{
    private List<Credit> allCredits = new ArrayList<Credit>();

    private Integer state = 0; //1表示有钱

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
        this.notifyCredits();
    }

    public void borrow(Credit credit) {
        allCredits.add(credit);
    }

    public void notifyCredits() {
        allCredits.forEach(credit -> credit.takeMoney());
    }
}
